package com.sky.mapper;

import com.sky.anotation.AllFull;
import com.sky.dto.EmployeeSetStatus;
import com.sky.dto.PasswordEditDTO;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

//@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    /**
     * 添加员工
     * @param employee
     * @return
     */
    @AllFull(OperationType.INSERT)
    @Insert("insert into " +
            "employee " +
            "(username" +
            ", name" +
            ", password" +
            ", phone" +
            ", sex" +
            ", id_number" +
            ", status" +
            ", create_time" +
            ", update_time" +
            ", create_user" +
            ", update_user)" +
            "values " +
            "(#{username}" +
            ", #{name}" +
            ", #{password}" +
            ", #{phone}" +
            ", #{sex}" +
            ", #{idNumber}" +
            ", #{status}" +
            ", #{createTime}" +
            ", #{updateTime}" +
            ", #{createUser}" +
            ", #{updateUser})")
    Integer add(Employee employee);

    /**
     * 分页查询
     * @param name  查询名字
     * @param start 起始页面
     * @param pageSize 每页个数
     * @return
     */
    List<Employee> pageEmp(String name, Integer start, Integer pageSize);
//    List<Employee> pageEmp(Integer start, Integer pageSize);

    /**
     * 查询所有员工个数
     * @return
     */
    @Select("select count(*) from employee")
    Integer total();

    @AllFull(OperationType.UPDATE)
    @Update("update employee set status = #{status}, update_time = #{updateTime}, update_user = #{updateUser} where id = #{id};")
    Integer setStatus(EmployeeSetStatus employeeSetStatus);

    @AllFull(OperationType.UPDATE)
    @Update("update employee set password = #{newPassword}, update_time=#{updateTime}, update_user=#{updateUser} where id = #{empId};")
    Integer editPassWord(PasswordEditDTO passwordEditDTO);

    @Select("select id, name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user from employee where id = #{id}")
    Employee getempById(Integer id);

    @AllFull(OperationType.UPDATE)
    @Update("update employee set username=#{username}, name=#{name}, phone=#{phone}, sex=#{sex}, id_number=#{idNumber}, update_time=#{updateTime}, update_user=#{updateUser} where id=#{id}")
    Integer updateEmp(Employee employee);
}
